<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>

<style type="text/css">
	body{overflow-y:scroll;}
</style>

</head>


<body>
	
	
		
	 <script>
		 let page=null
	 $(function () {
		//返回支付页面
		if(sessionStorage.back){
			$('#back').show()
		}
	    $('#back').on('click',function () {
			location.href=sessionStorage.back
		})

		//保存地址
		$('#address_button').on('click',function () {
			let data={};
			//user
			data.id=sessionStorage.id
			//省，地址，邮编，姓名，手机
			data.sheng=$('#sheng').val()
			data.dizhi=$('#dizhi').val()
			data.youbian=$('#youbian').val()
			data.xingming=$('#xingming').val()
			data.phone=$('#phone').val()
            data=JSON.stringify(data)
			let ur='/jd_index?order=save_address&data='+data;    
			ur=encodeURI(ur)   
      fetch(ur, {
              method: 'GET',
              })
              .then((res)=>{
              return res.json() 
              })
              .then((res)=>{
				  console.log(res)
								if(res.ok==1){
																		alert('添加成功')
																		location.reload()
																	}
              })
              .catch(error => console.log('error is', error));


			
		})

	 })
	 </script>












   
   <div class="container">
   	
   	
   	 <h2>收货地址设置</h2>
   	<div class="row">
   		
	  <!-- <div class="col-sm-4">
	   
		  <div class="list-group" id="show_right">
		    <a href="#" class="list-group-item list-group-item-action">安全设置</a>
		    <a href="#" class="list-group-item list-group-item-action">收货地址</a>
		    <a href="#" class="list-group-item list-group-item-action">个人信息资料</a>
		  </div>
	  </div> -->
	  <!--.col-sm-4 end~~~-->
	  
	  <div class="col-sm-8" id="for_show_right">
	  	
	  	  <div id="datum" style="display: none;">
	  	  	
	  	  	<form class="form-inline" style="margin-bottom: 20px;">
			  <label for="password">原密码:</label>
			  <input type="password" class="form-control">
			  <label for="pwd">新密码:</label>
			  <input type="password" class="form-control">
			  <button type="submit" class="btn btn-primary">修改</button>
			</form>
			
			<form class="form-inline" style="margin-bottom: 20px;">
			  <label for="password">手机号:</label>
			  <input type="text" class="form-control">
			  <label for="pwd">手机号:</label>
			  <input type="text" class="form-control">
			  <button type="submit" class="btn btn-primary">修改</button>
			</form>
			
			<form class="form-inline" style="margin-bottom: 20px;">
			  <label for="password">原邮箱:</label>
			  <input type="email" class="form-control">
			  <label for="pwd">新邮箱:</label>
			  <input type="email" class="form-control">
			  <button type="submit" class="btn btn-primary">修改</button>
	  	  	</form>
	  	  </div>
	  	  
	  	  <div id="address">
	  	  	<div class="form-group">
	  	  	<label>填写省市区:</label>
		      <input type="text" class="form-control" id="sheng" placeholder="XX省XX市">
		      <label>收货地址:</label>
		      <input type="text" class="form-control" id="dizhi" placeholder="收货地址">
		      <label>邮编:</label>
		      <input type="text" class="form-control" id="youbian" placeholder="邮编">
		      <label>姓名:</label>
		      <input type="text" class="form-control" id="xingming" placeholder="姓名">
		      <label>手机号/座机全称:</label>
		      <input type="text" class="form-control" id="phone" placeholder="号码">
		      <br />
			  <button type="button" id="address_button" class="btn btn-primary">保存</button>
			  <button style="display: none" type="button" id="back" class="btn btn-primary">返回支付页面</button>
		    </div>
		    
		    <div id="for_address" style="font-size: 12px;border: 1px solid #ECECEC;border-radius:3px ;">
		    	<div class="row" style="padding: 10px;">
				  <div class="col-2" style="margin-left: 10px;">收货人</div>
				  <div class="col-2">所在地区</div>
				  <div class="col-3">详细地址</div>
				  <div class="col-1">邮编</div>
				  <div class="col-2">电话/手机</div>
				  <div class="col-1.5">操作</div>
				  <div class="col-1"></div>
				</div>
				<div id="address_show">

				</div>
			   
	  	  	</div>
	  	  	
					<script type="text/javascript">
					$(function () {


            //获取已保存的信息
						get_address()


						function get_address() {

							let data={}
							data.id=sessionStorage.id
							data=JSON.stringify(data)
							let ur='/jd_index?order=get_address&data='+data;    
							fetch(ur, {
							method: 'GET',
							})
							.then((res)=>{
							return res.json() 
							})
							.then((res)=>{
							
							 let cab=res[0].xf.address
							 
							 for (const i of cab) {
								   let html='<div class="row" style="padding: 10px;">'+
															'<div class="col-2" style="margin-left: 10px;">'+i.xingming+'</div>'+
															'<div class="col-2">'+i.sheng+'</div>'+
															'<div class="col-3">'+i.dizhi+'</div>'+
															'<div class="col-1">'+i.youbian+'</div>'+
															'<div class="col-2">'+i.phone+'</div>'+
															'<div class="col-1"><button type="button" class="btn btn-danger delete_address" style="height: 30px;font-size: 15px;line-height: 15px">删除</button></div>'+
														'</div>'

									 $('#address_show').append(html)
							 }

						})
						.then(()=>{
								
							   //删除一个收货地址
								 delete_address()
								 function delete_address() {
									 $('.delete_address').on('click',function () {
										let data={}
																data.sheng=$(this).parent().prev().prev().prev().prev().html()
																data.dizhi=$(this).parent().prev().prev().prev().html()
																data.youbian=$(this).parent().prev().prev().html()
																data.xingming=$(this).parent().prev().prev().prev().prev().prev().html()
																data.phone=$(this).parent().prev().html()
																data.id=sessionStorage.id
																data=JSON.stringify(data)
																let ur='/jd_index?order=delete_address&data='+data;  
																fetch(ur, {
																method: 'GET',
																})
																.then((res)=>{
																return res.json() 
																})
																.then((res)=>{
																	if(res.ok==1){
																		alert('删除成功')
																		location.reload()
																	}
																})
																.catch(error => console.log('error is', error));


									 })
								
									 
								 }
							                 
						})
						
						}
						 
					})


    
	  	  		
	  	  		
	  	  		
	  	  	</script>
	  	  	
	  	  </div><!--address  end~~~~~~-->
	  	  
	  	  
	  	  <div id="personal" style="display: none;">
	  	  	<div class="form-group">
	  	  	  <label>昵称:</label>
		      <input type="text" class="form-control" placeholder="昵称">
		      <label>生日:</label>
		      <input type="date" class="form-control" placeholder="邮编">
              <select>
		      	<option value="">男</option>
		      	<option value="">女</option>
		      </select>
							<br />
							
			  <button type="button" class="btn btn-primary">保存</button>
			 
		    </div>
	  	  </div>
	  	  
	  	 
	  	
	  	
	  </div>
	  <!--.col-sm-8 end~~~-->
	  
	    <script type="text/javascript">
	    	$('#show_right>a').click(function  () {
	    		
	    		$('#for_show_right>div').hide()

	    	    $('#for_show_right>div').eq($(this).index()).show()
	    		
	    	})
	    </script>
	</div><!--row end~~~-->

	<%- include foot%>
	
	</div><!--container end!!!-->


</body>
</html>